package com.taotao.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.taotao.EasyUIResult;
import com.taotao.SystemConstants;
import com.taotao.TaotaoResult;
import com.taotao.mapper.TbItemParamMapper;
import com.taotao.pojo.TbItem;
import com.taotao.pojo.TbItemParam;
import com.taotao.pojo.TbItemParamExample;
import com.taotao.service.TbItemParamService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author evader
 * @date 2020-09-24 21:27
 */
@Service
public class ItemParamServiceImpl implements TbItemParamService {
    @Autowired
    private TbItemParamMapper tbItemParamMapper;

    @Override
    public TaotaoResult selectByPrimaryKey(Long id) {
        TbItemParamExample condition=new TbItemParamExample();
        condition.createCriteria().andItemCatIdEqualTo(id);

        List<TbItemParam> tbItemParamList=tbItemParamMapper.selectByExampleWithBLOBs(condition);
        if(tbItemParamList.size() > 0) {
            return TaotaoResult.ok(tbItemParamList.get(0));
        }
        return TaotaoResult.build(SystemConstants.TAOTAO_RESULT_STATUS_ERROR, "未查询到数据");
    }

    @Override
    public EasyUIResult getItemList(int pageNum, int pageSize) {
        PageHelper.startPage(pageNum, pageSize);
        List<TbItemParam> tbItemList = tbItemParamMapper.selectByExampleWithBLOBs(new TbItemParamExample());
        PageInfo<TbItemParam> pageInfo = new PageInfo(tbItemList);
        long total = pageInfo.getTotal();
        return new EasyUIResult(total, tbItemList);
    }

    // 不破坏原来的单表语句，新建一个扩充方法
    @Override
    public EasyUIResult selectItemParamExt(int pageNum, int pageSize) {
        // 关闭自动分页，开启手动分页
//        PageInterceptor pageInterceptor = new PageInterceptor();
//        Properties properties = new Properties();
//        properties.setProperty("supportMethodsArguments", "false");
//        pageInterceptor.setProperties(properties);

        PageHelper.startPage(pageNum, pageSize);
        List<TbItemParam> tbItemList = tbItemParamMapper.selectItemParamExt();
        PageInfo<TbItem> pageInfo = new PageInfo(tbItemList);
        long total = pageInfo.getTotal();
        return new EasyUIResult(total, tbItemList);
    }
}
